package functii.trigonometrice;

import operatori.Cat;
import functii.Functie;
import functii.elementare.Putere;

public class Ctg extends Functie{
    public static double calcul(double aux1){
        return 1/Math.tan(aux1);
    }

    public double calcul(){
        if(fStang == null)
            System.exit(1);
        return calcul(fStang.calcul());
    }

    public String derivare(){
        if(fStang == null)
            System.exit(1);
        return concatTermeni(Cat.concatTermens("-1.0", Putere.concatTermens(Sin.concatTermeni(fStang.derivare()))));
    }

    public double calculDerivata(){
    	if(fStang == null)
            System.exit(1);
        return Cat.Calcul(-1.0, Putere.calcul(Sin.calcul(fStang.calculDerivata())));
    }

    public String toString(){
    	if(fStang == null)
            System.exit(1);
        return concatTermeni(Cat.concatTermens("-1.0", Putere.concatTermens(Sin.concatTermeni(fStang.derivare()))));
    }

    public static String concatTermeni(String aux1){
        String aux;
        int nrP;

        nrP = aux1.charAt(0) == '(' ? 0 : 2;

        aux = "ctg";
        if(nrP != 0) aux += "(";
        aux += aux1;
        if(nrP != 0) aux += ")";

        return aux;
    }
}
